/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package aspect.example;
import aspect.entity.Entity;
import aspect.entity.behavior.Behavior;
import aspect.physics.Motion;
/**
*
* @author vincent
*/
public class FollowEntity extends Behavior {
private final Entity entity;
private final float maxSpeed;
public FollowEntity(Entity entity) {
this.entity = entity;
this.maxSpeed = entity.getBehavior(Motion.class).velocity.mag();
}
@Override
public void update() {
Motion m = ent.getBehavior(Motion.class);
m.acceleration = entity.transform.position.minus(ent.transform.position).normalize().times(10.0f);
if (m.velocity.mag() > maxSpeed) {
m.velocity = m.velocity.normalize().times(maxSpeed);
}
ent.transform.setForward(m.velocity);
}
}